﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.Collections.Generic;
using Jy123.Common;

namespace Jy123.Web.Module.Club
{
    public partial class SelectModule : System.Web.UI.Page
    {
        private int userId;
        private Jy123.Model.User_Main user;
        protected void Page_Load(object sender, EventArgs e)
        {
            string key = "UserID";
            string userIdString = Cookie.getCookie(key);
            if (string.IsNullOrEmpty(userIdString))
            {
                Response.Redirect("/");
            }
            if (!string.IsNullOrEmpty(userIdString))
            {
                userId = int.Parse(userIdString);
                Jy123.BLL.Venues.VModule BLLVModule = new Jy123.BLL.Venues.VModule();
                Jy123.BLL.Public_JType BLLJType = new Jy123.BLL.Public_JType();
                Jy123.BLL.User_Main BLLUser = new Jy123.BLL.User_Main();
                Jy123.BLL.Module_Main BLLModule = new Jy123.BLL.Module_Main();
                Jy123.BLL.Public_SportType BLLSportType = new Jy123.BLL.Public_SportType();

                List<Jy123.Model.Module_Main> listModule = BLLModule.GetModelList("FUser = " + userId.ToString());
                List<Jy123.Model.Public_SportType> listSportType = BLLSportType.GetModelList(string.Empty);
                Dictionary<int, string> dicSport = new Dictionary<int, string>();
                foreach (Jy123.Model.Public_SportType sportType in listSportType)
                {
                    dicSport.Add(sportType.ID, sportType.Logo);
                }
                List<Jy123.Model.Public_JType> listJType = BLLJType.GetModelList("JFather = '1' OR JFather = '2' OR JFather = '3'");
                Dictionary<int, Jy123.Model.Public_JType> dicJType = new Dictionary<int, Jy123.Model.Public_JType>();
                foreach (Jy123.Model.Public_JType JType in listJType)
                {
                    dicJType.Add(JType.ID, JType);
                }
                string html = Cache["selectmodule"].ToString();
                StringBuilder sbString = new StringBuilder();
                if (listModule.Count > 0)
                {
                    foreach (Jy123.Model.Module_Main cModule in listModule)
                    {
                        string strLi = Cache["selectmoduleli"].ToString();
                        Jy123.Model.Public_JType JType = dicJType[cModule.FJType.Value];
                        if (!string.IsNullOrEmpty(JType.Model))
                        {
                            strLi = strLi.Replace("$ImgSrc$", JType.Model);
                        }
                        else
                        {
                            strLi = strLi.Replace("$ImgSrc$", "/Images/Module/Module.gif");
                        }
                        string strHref = string.Empty;
                        if (JType.JFather.Value == 1)
                        {
                            strHref = string.Format("href = /Module/Venues/MyVenues.aspx?VenuesId={0}", cModule.ID.ToString());
                        }
                        else if (JType.JFather.Value == 2)
                        {
                            if (JType.FSportType.Value == 13 || JType.FSportType.Value == 14)
                            {
                                strHref = string.Format("href = /Module/CarClub/MyClub.aspx?ClubId={0}", cModule.ID.ToString());
                            }
                            else
                            {
                                strHref = string.Format("href = /Module/Club/MyClub.aspx?ClubId={0}", cModule.ID.ToString());
                            }

                        }
                        else {
                            strHref = string.Format("href = /Module/TCenter/MyTCenter.aspx?TCenterId={0}", cModule.ID.ToString());
                        }
                        strLi = strLi.Replace("$Href$", strHref);
                        strLi = strLi.Replace("$ModuleName$", JType.JName);
                        sbString.Append(strLi);
                    }
                    html = html.Replace("$Li$", sbString.ToString());
                    html = html.Replace("$UserId$", userId.ToString());
                    Response.Write(html);
                }
                else
                {
                    string msg = string.Empty;
                    //msg = "<script>window.location='CreateModule.aspx'</script>";
                    msg = "<script>$.moonbox.loadAjax('/Module/Club/CreateModule.aspx')</script>";
                    Response.Write(msg);
                }
            }
            else
            {
                //找不到UserId，返回首页,目前暂时返回空值
            }
        }
    }
}
